package com.lujianfei.netease_android_canvas.utils

import android.content.Context
import android.util.DisplayMetrics


object DensityUtils {
    fun getScreenWidth(context: Context): Int {
        val resources = context.resources
        val dm: DisplayMetrics = resources.displayMetrics
        val density1 = dm.density
        return dm.widthPixels
    }
    fun getScreenHeight(context: Context): Int {
        val resources = context.resources
        val dm: DisplayMetrics = resources.displayMetrics
        val density1 = dm.density
        return dm.heightPixels
    }
    fun dip2px(context: Context, dpValue: Float): Int {
        val scale = context.resources.displayMetrics.density
        return (dpValue * scale + 0.5f).toInt()
    }

    fun px2dip(context: Context, pxValue: Float): Int {
        val scale = context.resources.displayMetrics.density
        return (pxValue / scale + 0.5f).toInt()
    }
}